package no.uib.kwikktaim.gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSlider;
import javax.swing.KeyStroke;

/**
 * Method for getting the menu of the application. It's a factory, which is a
 * design pattern for getting instances without using a constructor.
 *
 */
public class MenuFactory {

	/**
	 * Made private because this class should not be instantiated.
	 */
	private MenuFactory() {}

	/**
	 * Factory method for getting the whole Menu
	 * @return
	 */
	public static JMenuBar getMenu() {
		JMenuBar menu = new JMenuBar();

		menu.add(addFileMenu());
		menu.add(addMediaMenu());
		menu.add(addPlaylistMenu());
		menu.add(addAboutMenu());

		return menu;
	}

	/**
	 * Ensembles the playlist menu
	 * @return
	 */
	private static JMenu addPlaylistMenu() {
		JMenu playList = new JMenu("Playlist");

		JMenuItem removeItem = new JMenuItem("Remove item");
		JMenuItem newItem = new JMenuItem("Add item...");
		JMenuItem clearList = new JMenuItem("Clear playlist");
		//TODO - Implement sorting of list
//		JMenuItem sortList = new JMenuItem("Sort playlist");

		playList.add(removeItem);
		playList.add(newItem);
		playList.add(clearList);
//		playList.add(sortList);

		return playList;
	}

	/**
	 * Ensembles the about menu
	 * @return
	 */
	private static JMenu addAboutMenu() {
		JMenu about = new JMenu("Help");
		JMenuItem aboutUs = new JMenuItem("About us...");

		about.add(aboutUs);
		return about;
	}

	/**
	 * Ensembles the media menu
	 * @return
	 */
	private static JMenu addMediaMenu() {
		JMenu menuMedia = new JMenu("Media");

		JMenuItem menuViewFullScreen = new JMenuItem("Full Screen");
		JMenuItem menuMediaInfo = new JMenuItem("Media Information...");
		JMenuItem menuPlayBackSpeedIncrease = new JMenuItem("Increase Speed");
		JMenuItem menuPlayBackSpeedDefault = new JMenuItem("Default Speed");
		JMenuItem menuPlayBackSpeedDecrease = new JMenuItem("Decrease Speed");

		menuMedia.add(menuViewFullScreen);
		menuMedia.add(menuMediaInfo);
		menuMedia.addSeparator();
		menuMedia.add(menuPlayBackSpeedIncrease);
		menuMedia.add(menuPlayBackSpeedDefault);
		menuMedia.add(menuPlayBackSpeedDecrease);

		// Accelerators
		menuPlayBackSpeedIncrease.setAccelerator(KeyStroke.getKeyStroke(
		        KeyEvent.VK_PLUS, ActionEvent.CTRL_MASK));

		menuPlayBackSpeedDefault.setAccelerator(KeyStroke.getKeyStroke(
		        KeyEvent.VK_EQUALS, ActionEvent.CTRL_MASK));

		menuPlayBackSpeedDecrease.setAccelerator(KeyStroke.getKeyStroke(
		        KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK));


		return menuMedia;
	}

	/**
	 * Ensembles the file menu
	 * @return
	 */
	private static JMenu addFileMenu() {
		JMenu file = new JMenu("File");
		JMenuItem quit = new JMenuItem("Quit");

		// Accelerators
		quit.setAccelerator(KeyStroke.getKeyStroke(
		        KeyEvent.VK_Q, ActionEvent.CTRL_MASK));

		file.add(quit);

		return file;
	}
}
